/*
 * Pratama Nur Wijaya (c) 2013 
 * 
 * Project       : OngkirJNE
 * Filename      : Fr_Input.java
 * Creation Date : May 17, 2013 time : 5:20:04 PM
 *
 */

package id.pratama.ongkirjne.fragment;

import id.pratama.ongkirjne.R;
import id.pratama.ongkirjne.Utils;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;

import com.actionbarsherlock.app.SherlockFragment;

public class Fr_Input extends SherlockFragment implements OnClickListener
{
	Fr_inputListener	mCallback;

	public interface Fr_inputListener
	{
		public void onFragmentInputButtonClick(Bundle b);
	}

	private AutoCompleteTextView	inputAsal;
	private AutoCompleteTextView	inputTujuan;
	private EditText				inputBerat;
	private Button					btnProses;

	private String[]				arrayKota	=
												{
			"AMBON",
			"BANDAACEH",
			"BANDUNG",
			"BANJARMASIN",
			"BATAM",
			"BALIKPAPAN",
			"BANDARLAMPUNG",
			"BENGKULU",
			"BEKASI",
			"BOGOR",
			"CILEGON",
			"CIREBON",
			"CILACAP",
			"DEPOK",
			"DENPASAR",
			"GORONTALO",
			"JAMBI",
			"JAKARTA",
			"JAYAPURA",
			"KENDARI",
			"KUPANG",
			"MALANG",
			"MAKASAR",
			"MATARAM",
			"MANADO",
			"MEDAN",
			"PADANG",
			"PALEMBANG",
			"PALU",
			"PALANGKARAYA",
			"PANGKALPINANG",
			"PEKANBARU",
			"PONTIANAK",
			"SAMARINDA",
			"SEMARANG",
			"SUKABUMI",
			"SURABAYA",
			"TERNATE",
			"SOLO",
			"YOGYAKARTA"
												};

	public static final String		TAG_ASAL	= "asal";
	public static final String		TAG_TUJUAN	= "tujuan";
	public static final String		TAG_BERAT	= "berat";

	private static final String		TAG			= Fr_Input.class.getName();

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
	{
		Utils.TRACE(TAG, "oncreateview");
		View v = inflater.inflate(R.layout.fr_input, container, false);

		inputAsal = (AutoCompleteTextView) v.findViewById(R.id.inputKotaAsal);
		inputTujuan = (AutoCompleteTextView) v.findViewById(R.id.inputKotaTujuan);
		inputBerat = (EditText) v.findViewById(R.id.inputBerat);
		btnProses = (Button) v.findViewById(R.id.btnProses);

		btnProses.setOnClickListener(this);

		return v;
	}

	@Override
	public void onCreate(Bundle savedInstanceState)
	{

		super.onCreate(savedInstanceState);
		Utils.TRACE(TAG, "oncreate");
	}

	@Override
	public void onAttach(Activity activity)
	{
		Utils.TRACE(TAG, "onattach");
		super.onAttach(activity);
		try
		{
			mCallback = (Fr_inputListener) activity;
		} catch (ClassCastException e)
		{
			throw new ClassCastException(activity.toString() + "must implement fr input listener");
		}
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState)
	{
		Utils.TRACE(TAG, "on activity created");
		super.onActivityCreated(savedInstanceState);
		setDataSpinner();
	}

	@Override
	public void onStart()
	{
		super.onStart();
		Utils.TRACE(TAG, "onstart");
	}

	@Override
	public void onClick(View v)
	{
		Utils.TRACE(TAG, "onclick");
		Bundle b = new Bundle();
		b.putString(TAG_ASAL, inputAsal.getText().toString());
		b.putString(TAG_TUJUAN, inputTujuan.getText().toString());
		b.putString(TAG_BERAT, inputBerat.getText().toString());

		mCallback.onFragmentInputButtonClick(b);

	}

	private void setDataSpinner()
	{

		ArrayAdapter<String> adapterKota = new ArrayAdapter<String>(getActivity(),
				android.R.layout.select_dialog_item, arrayKota);

		inputAsal.setAdapter(adapterKota);
		inputTujuan.setAdapter(adapterKota);

	}

}
